<template>

  <el-dialog :title="title" :visible.sync="open" width="90%" append-to-body :close-on-click-modal="false" v-dialogDrag>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入姓名"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="项目编号" prop="projectCode">
        <el-input v-model="queryParams.projectCode" placeholder="请输入项目编号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品编号" prop="goodsCode">
        <el-input v-model="queryParams.goodsCode" placeholder="请输入产品编号"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="产品名称" prop="goodsName">
        <el-input v-model="queryParams.goodsName" placeholder="请输入产品名称"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="工序名称" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入姓名"
                  clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table border v-loading="loading" :data="dataList" @selection-change="handleSelectionChange" ref="table"
      :max-height="tableMaxHeight">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column sortable label="项目编号" align="center" prop="projectCode"/>
      <el-table-column sortable label="产品编号" align="center" prop="goodsCode"/>
      <el-table-column sortable label="产品名称" align="center" prop="goodsName" show-overflow-tooltip/>
      <el-table-column sortable label="产品型号" align="center" prop="goodsModel"/>
      <el-table-column sortable label="工序名称" align="center" prop="name"/>
      <el-table-column label="工序产品名称" align="center" prop="gongxuName"/>
      <el-table-column label="工序产品型号" align="center" prop="gongxuModel"/>
      <el-table-column sortable label="姓名" align="center" prop="userName"/>
      <el-table-column sortable label="报工时间" align="center" prop="doTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.doTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column sortable label="报工数量" align="center" prop="count"/>
      <el-table-column sortable label="合格数量" align="center" prop="successCount"/>
      <el-table-column sortable label="不合格数量" align="center" prop="errorCount"/>
      <el-table-column sortable label="合格总价" align="center" prop="allMoney"/>
      <el-table-column sortable label="合格率(%)" align="center" prop="successLv"/>
      <!--<el-table-column sortable label="单价" align="center" prop="money"/>-->
      <!--<el-table-column align="center" label="状态" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.baogong_status" :value="scope.row.status"/>
        </template>
      </el-table-column>-->
      <!--<el-table-column sortable label="质检日期" align="center" prop="zhijianDate" width="180">
          <template slot-scope="scope">
              <span>{{ parseTime(scope.row.zhijianDate, '{y}-{m}-{d}') }}</span>
          </template>
      </el-table-column>
      <el-table-column sortable label="质检人" align="center" prop="zhijianUser"/>-->
      <el-table-column label="备注" align="center" prop="remark"/>

    </el-table>


    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList"/>

  </el-dialog>
</template>

<script>
  import {
    deleteAction,
    getAction
  } from '@/api/manage'

  export default {
    name: "ShengchanDoGoodsSaleForm",
    dicts: ['baogong_status'],
    components: {
    },
    data() {
      return {
        title: '',
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 销售产品物料选用明细表格数据
        dataList: [],
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name:null,
          goodsName:null,
          goodsCode:null,
          projectCode: null,
          xuhao: null,
          doTime: null,
          userId: null,
          userName: null,
          money: null,
          count: null,
          allMoney: null,
          parentId: null,
          successCount: null,
          errorCount: null,
          successLv: null,
          status: null,
          zhijianDate: null,
          zhijianUser: null,
          zhijianId: null,
          saleId: null,
          goodsId: null,
        },
        url: {
          list: '/goodsSaledoGongxuUserMoney/goodsSaledoGongxuUserMoney/listAndParent',
        },
        tableMaxHeight: window.innerHeight - 320,
      };
    },
    created() {
      window.addEventListener('resize', this.getTableHeight);
    },
    destroyed() {
      window.removeEventListener('resize', this.getTableHeight)
    },
    methods: {
      show(row) {
        this.open = true;
        this.title = "1自制产品记录明细";
        this.queryParams.saleId = row.id;
        //this.queryParams.saleId = row.goodsSaleId;
        // this.queryParams.goodsId = row.goodsId;
        // this.queryParams.goodsCode = row.materialsCode;
        // this.queryParams.projectCode = row.ipoNo;
        this.getList();
      },
      /** 查询销售产品物料选用明细列表 */
      getList() {
        this.loading = true;
        getAction(this.url.list, this.queryParams).then(response => {
          this.dataList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      getTableHeight() {
        this.tableHeight = window.innerHeight - 320
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length !== 1
        this.multiple = !selection.length
      },
    }
  };
</script>
